<template>
	<view id="page">
		<nav-bar :navH="navH" :isTabar="true" :isHome="false" :pageName="title"></nav-bar>
        <block v-if="hasRes">
			<view class="celebrity" v-for="(it, k1) in lists" :key="k1">
				<view class="store">
					<view class="col-9 lt" @click="goCeleHome(it.id)">
						<image :src="it.img" lazy-load="true" class='icon' @error="imgError(k1)"></image><text>{{it.name}}</text>
						<image src='../../static/4.png' mode="widthFix" lazy-load="true" class="vip"></image>
					</view>
					<view class="col-3 rt">
						<text class="btn" @click="setFllow(it.id, k1)" v-if="it.is_attention === 0">关注</text><text class="btn" v-else>已关注</text>
					</view>
				</view>
				<view class='flex list'>
					<block v-for="(it, k2) in it.zx_list" :key="k2">
						<view class="flex-i item" @click="goDetail(it.id)">
							<view class="pic">
								<image :src="it.imgs" mode='widthFix' lazy-load="true" @error="imgError2(k1, k2)"></image>
							</view>
							<text class="title">{{it.title}}</text>
							<image src='../../static/9.png' mode="widthFix" lazy-load="true" class="isvideo" v-if="it.is_video == 1"></image>
						</view>
					</block>
				</view>
			</view>
		</block>
		<view class="nocont" v-else>暂无内容</view>
		<view class="nomore" v-if="isLoad"><image src='../../static/nomore_img.png' mode="widthFix"></image><text>没有更多了~</text></view>
		<tab-bar :selected="3"></tab-bar>
	</view>
</template>

<script>
	import app from '../../common/index.js'
	export default {
		data() {
			return {
				title: '名人堂',
				navH: null,
				userInfo: {},
				hasRes: true,
				isLoad: false,
				page: 1,
				size: 5,
				lists: [],
			}
		},
		onLoad() {
			this.navH = this.$store.state.navHeight;
			// 获取本地用户信息
			this.userInfo = uni.getStorageSync('uinfo');
			this.getFamous();
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.page = 1;
			this.lists = [];
			// 获取本地用户信息
			this.userInfo = uni.getStorageSync('uinfo');
			this.getFamous();
			uni.stopPullDownRefresh();
		},
		// 上划加载
		onReachBottom() {
			if(!this.isLoad) {
				this.page = this.page+1;
				this.getFamous();
			}
		},
		// 分享转发
		onShareAppMessage() {
			return {
				title: '爱美指南针',
				path: 'pages/index/index',
			}
		},
		methods: {
			/**
			 * @des 登录提示框
			 */
			isShow() {
				this.isLogin = false;
			},
			/**
			 * @des 获取名人
			 */
			getFamous() {
				app.request({
					url: 'entry/wxapp/FamousDaKa',
					data: {
						page: this.page,
						pagesize: this.size,
						user_id: this.userInfo.id,
					}
				}, (ret) => {
					console.log(ret.data);
					let d = ret.data, tmpData = this.lists, len = d.data.length;
					if (d.total > 0) {
						this.hasRes = true;
						this.lists = tmpData.concat(d.data);
						this.isLoad = len < this.size ? true : false;
					} else {
						this.hasRes = false;
					}
				})
			},
			/**
			 * @des 关注
			 */
			setFllow(id, i) {
				app.request({
					url: 'entry/wxapp/Attention',
					data: {
						guan_user: this.userInfo.id,
						bguan_user: id,
					}
				}, (ret) => {
					this.lists[i]['is_attention'] = 1;
				})
			},
			/**
			 * @des 打开大咖主页
			 */
			goCeleHome(id) {
				uni.navigateTo({
					url: '../celebrityhome/index?id=' + id
				})
			},
			/**
			 * @des 打开问答详情
			 */
			goDetail(id) {
				uni.navigateTo({
					url: '../detail/index?qid=' + id
				})
			},
			/**
			 * @des 处理错误图片
			 */
			imgError(i) {
				let tmpLists = this.lists;
				tmpLists[i].img = '../../static/avatars_default.png';
				this.lists = tmpLists;
			},
			imgError2(i1, i2) {
				let tmpLists = this.lists;
				tmpLists[i1].zx_list[i2].imgs = '../../static/default.jpg';
				this.lists = tmpLists;
			}
		}
	}
</script>

<style>
	.celebrity {margin-bottom: 20upx; background-color: #fff;}
	/* 图文列表 */
	.flex-i {flex: 1; margin: 0 10upx;}
	.list {margin: 0 -10upx; padding: 0 25upx 20upx 25upx;}
	.list .item {position: relative; margin-bottom: 20upx; padding-bottom: 10upx; box-shadow: 0 0 18upx #ddd; border-radius: 0 0 3px 3px; background-color: #fff;}
	.list .item .pic {height: 480upx; background-color: #f3f8f8; border-radius: 3px 3px 0 0; overflow: hidden;}
	.list .item .title {height: 90upx;}
	.list .item .isvideo {position: absolute; top: 26upx; right: 26upx; width: 50upx; height: 50upx; border-radius: 100%; z-index: 113;}
</style>
